/*
 * Saphre - Suffix Arrays for Phrase Extraction
 * Copyright (C) 2013 
 * Dale Gerdemann - Tübingen, Germany 
 * Niko Schenk - Frankfurt am Main, Germany
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package saphre.commands;

import saphre.core.SaphreCommandInterpreter;
import util.Interval;
import saphre.core.Store;
import saphre.core.SuffixArray;
import util.PPrint;

import java.util.regex.Matcher;

public class CmdShowInterval2 {
    
    Interval paFound;
    Interval saFound;
    private final SaphreCommandInterpreter saphreCommandInterpreter;

    public CmdShowInterval2(SaphreCommandInterpreter saphreCommandInterpreter) {
        this.saphreCommandInterpreter = saphreCommandInterpreter;
    }

    public void CmdShowInterval2(Store store, SuffixArray sa, SuffixArray pa, Matcher m) {
        String g1 = m.group(1);
        String g2 = m.group(2);
        String g3 = m.group(3);
        String g4 = m.group(4);

        Interval inter = saFound;
        if (g1.equals("pa")) {
            inter = paFound;
        }
        int offset = 0;
        if (g2 != null) {
            offset = Integer.parseInt(g2);
        }
        int length = inter.tf();
        if (g3 != null) {
            length = Integer.parseInt(g3);
        }
        int depth = 5;
        if (g4 != null) {
            depth = Integer.parseInt(g4);
        }

        PPrint.ppInterval(sa, pa, store, depth,
                inter.lb() + offset,
                inter.lb() + offset + length - 1);
    }
}